home *** CD-ROM | disk | FTP | other *** search
- Path: frco.com!usenet
- From: Jadam@tcmail.frco.com (Jim Adam)
- Newsgroups: comp.lang.c++
- Subject: Re: inherited classes / functions
- Date: 7 Feb 1996 19:32:33 GMT
- Organization: Fisher Rosemount Systems
- Message-ID: <4fauoh$im2@rolaids.frco.com>
- References: <Pine.A32.3.91.960202182844.45749A-100000@asterix.uni-muenster.de>
- NNTP-Posting-Host: primrose.frco.com
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.11
-
- In article
- <Pine.A32.3.91.960202182844.45749A-100000@asterix.uni-muenster.de>,
- kutzeln@uni-muenster.de says...
-
- >when using inherited virtual functions, how can I simply call the
- >"inherited" function without knowing the name of the parent class?
- >
- > While I am developing a graphical user interface, I sometimes need to
- >"insert" a class in the class hierarchy, so I don't want to change all
- > the "subclasses" code when "inserting" the new class. In Turbo Pascal
- > there was the keyword "inherited"
-
- The suggested approach (see _The Design and Evolution of C++_, B.
- Stroustrup, Section 13.6) is:
-
- class foreman : public employee {
- typedef employee inherited;
- };
-
- class manager : public foreman {
- typedef foreman inherited;
- };
-
- // ETC.
-
- Then, rather than:
-
- int manager::doSomething() {
- return foreman::doSomething();
- }
-
- you say
-
- int manager::doSomething() {
- return inherited::doSomething();
- }
-
- Note, I've also seen people use "typedef foreman Base" and
- other things rather than "inherited." --Anyway, this keeps
- the implementation of the derived classes from having to
- change. Only the definition part has to change.
-
- Jim
-
-
-
-